package com.aegis.core.enums;

import cn.dev33.satoken.error.SaErrorCode;
import cn.dev33.satoken.exception.SaTokenException;
import cn.dev33.satoken.router.SaHttpMethod;
import com.aegis.core.exceptions.AegisException;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author wuweixin
 *
 * @Version 1.0
 * @Descritube
 */
public enum AegisHttpMethod {

    GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS,
    ALL;

    private static final Map<String, AegisHttpMethod> map = new HashMap<>();

    static {
        for (AegisHttpMethod reqMethod : values()) {
            map.put(reqMethod.name(), reqMethod);
        }
    }


    public static AegisHttpMethod toEnum(String method) {
        if (method == null) {
            throw new AegisException("method不能为空");
        }
        AegisHttpMethod reqMethod = map.get(method.toUpperCase());
        if (reqMethod == null) {
            throw new AegisException("无效method：" + method);
        }
        return reqMethod;
    }

}
